package com.ruoyi.web.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.admin.domain.vo.request.atricle.AtricleAddRequest;
import com.ruoyi.admin.domain.vo.request.atricle.AtriclePageJoinRequest;
import com.ruoyi.admin.domain.vo.request.atricle.AtriclePageRequest;
import com.ruoyi.admin.domain.vo.request.atricle.AtricleUpdateRequest;
import com.ruoyi.admin.domain.vo.response.atricle.AtriclePageJoinResponse;
import com.ruoyi.admin.domain.vo.response.atricle.AtriclePageResponse;
import com.ruoyi.admin.domain.vo.response.atricle.AtricleResponse;
import com.ruoyi.admin.service.AtricleService;
import com.ruoyi.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 货号表(Atricle)Controller类
 *
 * @author jianhan
 * @date 2023-01-31 10:49:28
 */
@Api(value = "后台货号表 Controller", tags = {"后台货号表"})
@RestController
@RequestMapping("/api/atricle")
public class AtricleController {

    @Autowired
    private AtricleService atricleService;

    /**
     * 根据id获取数据
     *
     * @author jianhan
     * @date 2023-01-31 10:49:28
     **/
    @ApiOperation(value = "根据id获取数据", notes = "根据id获取数据")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "path", dataType = "Long")
    @GetMapping("/{id}")
    public Result<AtricleResponse> get(@PathVariable Long id) {
        return atricleService.getId(id);
    }


    /**
     * 分页获取货号表列表
     *
     * @author jianhan
     * @date 2023-01-31 10:49:28
     **/
    @ApiOperation(value = "分页获取货号表列表", notes = "分页获取货号表列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页码", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "查询数量", paramType = "query", dataType = "Integer")
    })
    @GetMapping
    public Result<AtriclePageResponse> pageList(@Valid AtriclePageJoinRequest req) {
        return atricleService.page(new Page<>(req.getPageNum(), req.getPageSize()), req);
    }

    /**
     * @description: 下拉查询
     * @param:
     * @return:
     * @author: jianhan
     * @date: 2023/2/7 11:39
     **/
    @ApiOperation(value = "下拉查询", notes = "下拉查询")
    @GetMapping("/list")
    public Result<List<AtriclePageJoinResponse>> selectList(AtriclePageJoinRequest req){
        return atricleService.selectList(req);
    }


    /**
     * 添加货号表
     *
     * @author jianhan
     * @date 2023-01-31 10:49:28
     **/
    @ApiOperation(value = "添加货号表", notes = "添加货号表")
    @PostMapping
    public Result add(@RequestBody @Valid AtricleAddRequest req) {
        return atricleService.add(req.getAtricleModel());
    }


    /**
     * 修改货号表
     *
     * @author jianhan
     * @date 2023-01-31 10:49:28
     **/
    @ApiOperation(value = "修改货号表", notes = "修改货号表")
    @PutMapping()
    public Result update(@RequestBody @Valid AtricleUpdateRequest req) {
        return atricleService.update(req.getAtricleModel());
    }


    /**
     * 删除货号表
     *
     * @author jianhan
     * @date 2023-01-31 10:49:28
     **/
    @ApiOperation(value = "删除货号表", notes = "删除货号表")
    @ApiImplicitParam(name = "ids", value = "id集合,逗号隔开", required = true, paramType = "query", dataType = "String")
    @DeleteMapping("/{ids}")
    public Result update(@PathVariable String ids) {
        Boolean result = atricleService.removeByIds(Arrays.asList(ids.split(",")).stream().collect(Collectors.toList()));
        return Result.judge(result);
    }

}
